﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BaHuan.BusinessLayer;
using BaHuan.Common;
using BaHuan.Entities;
using System.Linq.Expressions;

namespace BaHuan
{
    public partial class FrmTimKiemChiNhanh : Form
    {
        private ChiNhanhKhachHangManagement chinhanhkhachhangMgt = new ChiNhanhKhachHangManagement();

        public FrmTimKiemChiNhanh()
        {
            InitializeComponent();
        }

        private void btnTimKiem_Click(object sender, EventArgs e)
        {
            string sTen = txtTimKiem.Text;
            ResultObj result = new ResultObj();
            result = chinhanhkhachhangMgt.GetAllChiNhanhKhachHang();

            List<ChiNhanhKhachHang> lstChiNhanhKhachHang = (from c in (List<ChiNhanhKhachHang>)result.Result
                                                            where c.Ten.Contains(sTen) || 
                                                            c.MaSoThue.Contains(sTen) ||
                                                            c.DienThoai.Contains(sTen) ||
                                                            c.DiaChi.Contains(sTen)
                                                            select c).ToList();
            dgvTimkiem.DataSource = lstChiNhanhKhachHang;
        }

        private void txtTimKiem_TextChanged(object sender, EventArgs e)
        {
            string sTen = txtTimKiem.Text.ToLower();
            ResultObj result = new ResultObj();
            result = chinhanhkhachhangMgt.GetAllChiNhanhKhachHang();

            List<ChiNhanhKhachHang> lstChiNhanhKhachHang = (from c in (List<ChiNhanhKhachHang>)result.Result
                                                            where c.Ten.Contains(sTen.ToLower()) ||
                                                            c.MaSoThue.Contains(sTen.ToLower()) ||
                                                            c.DienThoai.Contains(sTen.ToLower()) ||
                                                            c.DiaChi.Contains(sTen.ToLower())
                                                            select c).ToList();
            dgvTimkiem.DataSource = lstChiNhanhKhachHang;
        }             
    }
}
